<template>
	<el-container>
		<el-header>
			<div class="left-panel">
				<sc-export-button :auth="'stock.export'" :apiObj="apiObj" :search="search"></sc-export-button>
			</div>
			<div class="right-panel">
				<div class="right-panel-search">
					<el-select v-model="search.ware_id" filterable :placeholder="$t('goods.goods.ware')" @change="inChange" clearable>
						<el-option v-for="item in wareList" :key="item.id" :label="item.ware_name" :value="item.id" />
					</el-select>
					<el-input v-model="search.goods_name" :placeholder="$t('goods.goods.name')" clearable @keyup.enter="upsearch"></el-input>
					<el-input v-model="search.goods_code" :placeholder="$t('goods.goods.code')" clearable @keyup.enter="upsearch"></el-input>
					<el-button type="primary" icon="el-icon-search" @click="upsearch"></el-button>
				</div>
			</div>
		</el-header>
		<el-main class="nopadding">
			<scTable ref="table" :apiObj="apiObj"  show-summary remoteSummary row-key="id" stripe remoteSort>
                <!-- tableName="stockTable" :column="defaultColumn" :sumColumn="['curr_stock']" @sort-change="onSortChange" -->
				<el-table-column type="selection" width="50"></el-table-column>
				<el-table-column :label="$t('all.sort')" type="index" width="50" align="center"></el-table-column>
				<el-table-column :label="$t('goods.goods.name')" prop="goods_name" align="center"></el-table-column>
				<el-table-column :label="$t('goods.goods.nameen')" prop="goods.goods_name_eng" align="center"></el-table-column>
				<el-table-column :label="$t('goods.goods.code')" prop="goods_code" align="center"></el-table-column>
				<el-table-column :label="$t('goods.goods.category')" prop="cate_name" align="center"></el-table-column>
				<el-table-column :label="$t('ware.ware')" prop="ware_name" align="center"></el-table-column>
				<el-table-column :label="$t('ware.search.stocknumber')" prop="curr_stock" align="center"></el-table-column>
			</scTable>
		</el-main>
	</el-container>

	<save-dialog v-if="dialog.save" ref="saveDialog" @success="handleSaveSuccess" @closed="dialog.save = false"></save-dialog>

</template>

<script>
import saveDialog from './save'

export default {
	name: '查询1',
	components: {
		saveDialog
	},
	data() {
		return {
			dialog: {
				save: false
			},
			apiObj: this.$API.goods.stock,
			selection: [],
			search: {
				ware_id: null,
				order_by: 'desc',
				field: 'id'
			},
			wareList: [],
			defaultColumn: [
				{
					label: this.$t('goods.goods.name'),
					prop: "goods_name",
					width: "100"
				},
				{
					label: this.$t('goods.goods.code'),
					prop: "goods_code",
					width: "100"
				},
				{
					label: this.$t('goods.goods.category'),
					prop: "cate_name",
					width: "150",
				},
				{
					label: this.$t('ware.ware'),
					prop: "ware_name",
					width: "100",
				},
				{
					label: this.$t('ware.search.stocknumber'),
					prop: "curr_stock",
					width: "100",
					sortable: true
				},
			],
		}
	},
	mounted() {
		this.getWare()
	},
	methods: {
		//表格选择后回调事件
		selectionChange(selection) {
			this.selection = selection;
		},
		onSortChange(data) {
			if (data.order == 'ascending') {
				this.search.order_by = 'asc'
				this.search.field = data.prop
			}
			if (data.order == 'descending') {
				this.search.order_by = 'desc'
				this.search.field = data.prop
			}
			this.upsearch()
		},
		//搜索
		upsearch() {
			this.$refs.table.upData(this.search)
		},
		// 获取仓库
		async getWare() {
			var res = await this.$API.goods.ware.all.get();
			this.wareList = res.data;
		},
	}
}
</script>

<style></style>
